//
//  FileAssistModel.swift
//
//  Created by Ken on 2020/4/13
//  Copyright (c) . All rights reserved.
//

import Foundation
import SwiftyJSON

public class FileAssistModel {

  // MARK: Declaration for string constants to be used to decode and also serialize.
  private struct SerializationKeys {
      static let fName =  "f_name"
      static let cName =  "c_name"

      static let fDate =  "f_date"
      static let cDate =  "c_date"

    static let idKey = "id_key"
      static let fVouid =  "f_vouid"
      static let cVouid =  "c_vou_id"

      static let fUrl =  "f_url"
      static let cUrl =  "c_url"

  }

  // MARK: Properties
  public var fName: String?
  public var fDate: String?
  public var idKey: String?
  public var fVouid: String?
  public var fUrl: String?
  public var fNum: String?
  public var fData: Data?
  
 

  // MARK: SwiftyJSON Initializers
  /// Initiates the instance based on the object.
  ///
  /// - parameter object: The object of either Dictionary or Array kind that was passed.
  /// - returns: An initialized instance of the class.
  public convenience init(object: Any) {
    self.init(json: JSON(object))
  }

  /// Initiates the instance based on the JSON that was passed.
  ///
  /// - parameter json: JSON object from SwiftyJSON.
  public required init(json: JSON) {
      fName = json[SerializationKeys.fName].string.isSome ? json[SerializationKeys.fName].string :
      json[SerializationKeys.cName].string
      fDate = json[SerializationKeys.fDate].string.isSome ? json[SerializationKeys.fDate].string :
      json[SerializationKeys.cDate].string
      
      
      idKey = json[SerializationKeys.idKey].int.isSome ? "\(json[SerializationKeys.idKey].int!)" : json[SerializationKeys.idKey].string
      let vou = json[SerializationKeys.fVouid].int.isSome ? "\(json[SerializationKeys.fVouid].int!)" : json[SerializationKeys.fVouid].string
      let cvou = json[SerializationKeys.cVouid].int.isSome ? "\(json[SerializationKeys.cVouid].int!)" : json[SerializationKeys.cVouid].string
      fVouid = vou.isSome ? vou :cvou
      
      fUrl = json[SerializationKeys.fUrl].string.isSome ? json[SerializationKeys.fUrl].string :
      json[SerializationKeys.cUrl].string
  }

  /// Generates description of the object in the form of a NSDictionary.
  ///
  /// - returns: A Key value pair containing all valid values in the object.
  public func dictionaryRepresentation() -> [String: Any] {
    var dictionary: [String: Any] = [:]
      if let value = fName {
          dictionary[SerializationKeys.fName] = value
          dictionary[SerializationKeys.cName] = value

      }
      if let value = fDate {
          dictionary[SerializationKeys.fDate] = value
          dictionary[SerializationKeys.cDate] = value

      }
    if let value = idKey { dictionary[SerializationKeys.idKey] = value }
      if let value = fVouid {
          dictionary[SerializationKeys.fVouid] = value
          dictionary[SerializationKeys.cVouid] = value
      }
      if let value = fUrl {
          dictionary[SerializationKeys.fUrl] = value
          dictionary[SerializationKeys.cUrl] = value

      }
    return dictionary
  }

}
